import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import { logininfo } from '../api/api'
export default new Vuex.Store({
  state: {
    loginFlag: false,
    userInfo: {},
    modelFlag: false
  },
  mutations: {
    // state 全局初始状态
    change(state, payload) {
      state.loginFlag = payload.loginFlag
      state.userInfo = payload.userInfo
    },
    changemodel(state,payload){
      state.modelFlag = payload.modelFlag
    }
  },
  actions: {
    islogin(context) {
      // 判读是否是登录的状态，请求接口
      logininfo().then(res => {
        if (res.code == 0) {
          context.commit("change", { loginFlag: true, userInfo: res.userInfo })
        } else {
          context.commit("change", { loginFlag: false, userInfo:{} })
        }
      })
    }
  },
  modules: {
  }
})